<?php
namespace app\front\service\v2;

use app\front\service\GetMsgService;

class PersionCenter extends GetMsgService
{
    
    
    
    public function getWithdraw(){
        $openid= $this->getOpenId();
        $WithdrawMsg=$this->getWithdrawForOpenid($openid);
        $WithdrawMsg= json_decode(json_encode($WithdrawMsg),true);
        return  $WithdrawMsg;
    }

    public function getUserMsg(){
       $openid= $this->getOpenId();
      // logs("yeyeye.txt",  $openid);
      $userMeg= $this->existUserinfo($openid);
      if($userMeg){
        return $userMeg;
      }else{
          return false;
      }
    }
    
    public function getRedPackMsg(){
        $openid= $this->getOpenId();
        $RedPackMsg= $this->getRecordForOpenid($openid);  
        $RedPackMsg= json_decode(json_encode($RedPackMsg),true);
        for($i=0;$i<count($RedPackMsg,0);$i++){
            //保留两位小数后面的舍去
            $RedPackMsg[$i]['award_money']=  substr(sprintf("%.3f", $RedPackMsg[$i]['award_money']),0,-1); 
            $store= $this->getStoreForStoreid($RedPackMsg[$i]['store_id']);
            $RedPackMsg[$i]['store_name']=$store['store_name'];
        }
        return $RedPackMsg;
    }
    
    public function checkResidue($WithdrawMoney){
        $openid=$this->getOpenId();
        $userMsg=$this->existUserinfo($openid);
        $residue=bcsub($userMsg['money'],$WithdrawMoney,2);
        if($residue>=0){
            $userMsg['residue']=$residue;
            return $userMsg;
        }else{
            return false;
        }
    }
    
    public function checkIsMember(){
       $userMsg= getMemberMessageForOpenid($this->getOpenId());
       if( $userMsg['subscribe']==1){
           return true;
       }
       else{
           return false;
       }
        
    }
    
    public function changeUserMoney($userMsg,$residue){
        $userMsg['money']= $residue;
        $this->updateUserMoney($userMsg); 
    }
}

